// addressStore.js
import { defineStore } from 'pinia';

export const useAddressStore = defineStore({
  id: 'address',
  state: () => ({
    addresses: [], // 存储多个地址
  }),
  actions: {
    addAddress(address) {
      this.addresses.push(address);
    },
    setAddressAsDefault(addressId) {
      this.addresses.forEach(address => address.isDefault = address.id === addressId);
    },
    deleteAddress(areaCode) {
      console.log(`Attempting to delete address with areaCode: ${areaCode}`); // 调试日志
      this.addresses = this.addresses.filter(address => address.areaCode !== areaCode);
      console.log(`New addresses list: `, this.addresses); // 调试日志
    },
    getAllAddresses() {
      return this.addresses;
    }
  }
});
